import axios from '~/plugins/axios';

import * as types from '../../mutation-types/customer/index';

/**
 * 客户列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const customerList = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/customer/list', {
        params: preload || {}
    })
};

/**
 * 公海客户列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const customerSeas = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/customer/publiclist', {
        params: preload || {}
    });
};

/**
 * 领取公海客户
 *
 * @param commit
 * @param state
 * @param preload
 */
export const receiveCustomer = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/customer/receivecustomer', preload);
};

/**
 * 客户回归公海
 *
 * @param commit
 * @param state
 * @param preload
 */
export const returnCustomer = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/customer/returncustomer', preload);
};

/**
 * 分配/转移客户
 *
 * @param commit
 * @param state
 * @param preload
 */
export const transCustomer = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/customer/trans', preload);
};

/**
 * 删除客户
 *
 * @param commit
 * @param state
 * @param preload
 */
export const deleteResult = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/customer/delete', preload)
};

/**
 * 添加编辑客户
 *
 * @param commit
 * @param state
 * @param preload
 */
export const customerAdd = function({commit, state}, preload) {
    // 如果有客户id,为编辑,否则添加
    let url;
    if (preload.id) {
        url = "/customer/updateCustomerAndContact";
    } else {
        url = "/customer/add";
    }
    return axios.post(process.env.baseUrl + url, preload)

};

/**
 * 客户详情
 *
 * @param commit
 * @param state
 * @param preload
 */
export const customerDetail = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/customer/getCustomerInfo', {
        params: preload || {}
    });
};

/**
 * 客户联系人详情
 *
 * @param commit
 * @param state
 * @param preload
 */
export const customerContact = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/customerContact/getCustomerContactById', {
        params: preload || {}
    })
};

/**
 * 客户跟进列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const customerFollowList = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/follow/listFollowDetails', {
        params: preload || {}
    })
};

/**
 * 添加客户跟进记录
 *
 * @param commit
 * @param state
 * @param preload
 */
export const customerFollowAdd = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/follow/addFollow', preload);
};

/**
 * 省份数据接口
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getAllProvinceList = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/address/provincelist', {
        params: preload || {}
    })
        .then(function(response) {
            if (!response) {
                return
            }

let result = response.data;
            if (result && result.code === 0) {
                result.data.forEach((n, i) => {
                    n.children = [];
                });
                commit(types.PROVINCE_LIST, {
                    provinceList: result.data
                })
            }
        })
};

/**
 * 根据省获取城市接口
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getAllCityList = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/address/citylist', preload)
};

/**
 * 获取区数据接口
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getAllDistrictList = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/address/districtlist', preload)
};

export const getUserList = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/member/list', {
        params: preload
    });
};

export const getSalesCategoryList = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/dicttype/list?typeId=7', {
        params: preload || {}
    })
};


/**
 * 查询所属行业
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getIndustry = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/dicttype/list', {
        params: preload || {}
    })
};


/**
 * 获取管理的部门列表接口
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getOwnerDeptment = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/department/getOwnerDept', {
        params: preload || {}
    })
};


/**
 * 所属行业
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getIndustryList = function({commit, state}, preload) {
    // return axios.post(process.env.baseUrl + '/industry/getIndustryByParentCode', preload || {})
    return axios.post(process.env.baseUrl + '/industry/getIndustryTree', preload || {})
        .then((response) => {
            if (!response) {
                return
            }
            let result = response.data;
            if (result.code === 0) {
                var jobList = result.data;
                commit(types.INDUSTRY_LIST, {
                    industryList: jobList
                })
            }
        })
};

/**
 * 所属行业
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getIndustryChildren = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/industry/getIndustryByParentCode', preload || {})
};

/**
 * 拨打电话
 *
 * @param commit
 * @param state
 * @param preload
 */
export const callCustomer = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/recorddetail/callGet', preload || {})
};

/**
 * 接听电话
 *
 * @param commit
 * @param state
 * @param preload
 */
export const answerCall = function({commit, state}, preload) {
    return axios.post('http://127.0.0.1:3366/callAccept', preload || {})
};

/**
 * 挂断电话
 *
 * @param commit
 * @param state
 * @param preload
 */
export const callHang = function({commit, state}, preload) {
    return axios.post('http://127.0.0.1:3366/callHang', preload || {})
};

/**
 * 漏接电话管理
 *
 * @param commit
 * @param state
 * @param preload
 */
export const missedCall = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/recorddetail/missCall', preload || {})
};

/**
 * 品牌列表
 *
 * @param commit
 * @param state
 * @param preload
 */
export const getBrandListBySale = function({commit, state}, preload) {
    return axios.post(process.env.baseUrl + '/sauronBrand/getBrandListBySale', preload || {})
};

//模糊搜索品牌名称的运营员的

export const getSelfBrandsListcus = function({commit, state}, preload) {
    return axios.get(process.env.baseUrl + '/sauronBrand/getSelfBrandsListForSale', {
        params: preload || {}
    })
};